package com.huilang.demo1.before;

public interface Ilift {
    int OPENING_STATE= 0;
    int CLOSING_STATE= 1;
    int RUNNING_STATE= 2;
    int STOPPED_STATE= 3;

    void setState(int state);

    void open();
    void close();
    void run();
    void stop();
}
class Lift implements Ilift {
    private int state;
    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
        switch (state) {
            case OPENING_STATE:
                return;
            case CLOSING_STATE:
                System.out.println("电梯打开了...");
                setState(OPENING_STATE);
                return;
            case RUNNING_STATE:
                return;
            case STOPPED_STATE:
                System.out.println("电梯打开了...");
                setState(OPENING_STATE);
        }
    }

    @Override
    public void close() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯关闭了...");
                setState(CLOSING_STATE);
                return;
            case CLOSING_STATE:
                return;
            case RUNNING_STATE:
                return;
            case STOPPED_STATE:

        }
    }

    @Override
    public void run() {
        switch (state) {
            case OPENING_STATE:
                System.out.println("电梯运行了");
                setState(RUNNING_STATE);
                return;
            case CLOSING_STATE:
                return;
            case RUNNING_STATE:
                return;
            case STOPPED_STATE:

        }
    }

    @Override
    public void stop() {
        switch (state) {
            case OPENING_STATE:
                return;
            case CLOSING_STATE:
                System.out.println("电梯停止了...");
                setState(RUNNING_STATE);
                return;
            case RUNNING_STATE:
                return;
            case STOPPED_STATE:
                System.out.println("电梯停止 了...");
                setState(RUNNING_STATE);

        }
    }
}